/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQml 2.12
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.12
import org.ukui.tablet 1.0
import "./baseComponent"
import "."

TabletDesktopWindow {
    id: rootWindow
    signal desktopIsNotActived()
    property alias taskBar: itemView.taskBar
    objectName: "rootRectangle"
    anchors.fill: parent
    visible: true
    state: "Hide"

    Item {
        id: topLayer
        anchors.fill: parent
        z: 100
    }
    Item {
        id: groupPopupLayer
        anchors.fill: parent
        z: 99

        Rectangle {
            id: groupPopupBackground
            anchors.fill: parent
            color: openGLEnabled ? "transparent" : "gray"
            opacity: openGLEnabled ? 1 : 0.9
            visible: false

            FastBlur {
                anchors.fill: parent
                source: backgroundItem
                radius: 64
            }
            FastBlur {
                anchors.fill: parent
                source: itemView
                radius: 64
            }

            MouseArea {
                id: groupPopupBackgroundMouseArea
                anchors.fill: parent
                z: -1
                onClicked: {
                    GroupController.minimizeGroup()
                }
            }
        }
    }

    Rectangle {
        id: rootContent
        objectName: "contentRectangle"
        anchors.fill: parent
        color: "transparent"

        Item {
            id: pluginAnchorsItem
            anchors.fill: parent
        }

        TabletLauncherView {
            id: itemView
            pluginAnchorItem: pluginAnchorsItem
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.fill: parent
            viewMoel: modelManager.launcherModel
        }

        PageSwitchIndicator {
            id: pageIndicator
            visible: itemView.listViewItemCount() > 1
            anchors.bottom: parent.bottom
            y: 0
            anchors.bottomMargin: 176 * Style.tabletScaleFactor
            anchors.horizontalCenter: parent.horizontalCenter
            pageContainer: itemView.pageContainer
        }
    }

    states: [
        State {
            name: "Show"
            PropertyChanges {
                target: rootContent
                opacity: 1
                scale: 1
            }
        },
        State {
            name: "Hide"
            PropertyChanges {
                target: rootContent
                opacity: 0
                scale: 0.9
            }
        }
    ]
    transitions: Transition {
        ParallelAnimation {
            NumberAnimation { target: rootContent; properties: "width,height,opacity,scale"; duration: 200 }
        }
    }
}


